﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.orderDAL;

namespace dhSystemBLL.orderData
{
  public   class supplierListBLL
    {
      private supplierListTableAdapter _supplierListAdapter = null;
      private supplierListTableAdapter supplierListAdapter
        {
            get
            {
                if (_supplierListAdapter == null) _supplierListAdapter = new supplierListTableAdapter();
                return _supplierListAdapter;
            }
        }
        /// <summary>
      /// 查询供应商资料列表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public orderDataSet.supplierListDataTable getsupplierListAll()
        {
            try
            {
                return supplierListAdapter.GetDatasupplierListAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
      /// <summary>
      /// 查询供应商资料列表
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public orderDataSet.supplierListDataTable getsupplierListAllBysType()
      {
          try
          {
              return supplierListAdapter.GetDatasupplierListBysType ();
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 查询供应商资料列表
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public orderDataSet.supplierListDataTable GetDatasupplierListBysTypeNo()
      {
          try
          {
              return supplierListAdapter.GetDatasupplierListBysTypeNo();
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 查询供应商资料列表
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public orderDataSet.supplierListDataTable getsupplierListBysTypelike(string sName)
      {
          try
          {
              return supplierListAdapter.GetDatasupplierListBysTypelike (sName);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 查询供应商资料列表
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public orderDataSet.supplierListDataTable getsupplierListBysTypelikeNo(string sName)
      {
          try
          {
              return supplierListAdapter.GetDatasupplierListBysTypelikeNo (sName);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
        /// <summary>
      /// 根据编号查询供应商资料列表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public orderDataSet.supplierListDataTable getsupplierListAll(string sName)
        {
            try
            {
                return supplierListAdapter.GetDatasupplierListBysName (sName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
      /// 插入供应商资料列表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public int supplierListInsert(supplierListModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                supplierListDAL supplierList = new supplierListDAL(tn, conn);
                supplierList.supplierListInsert(row);
                tn.Commit();
                return i;

            }
            catch (SqlException ex)
            {
                tn.Rollback();
                if (ex.Number == 2627)
                {
                    throw new Exception("这个供应商编号已经存在");
                }


                throw new Exception(ex.Number.ToString() + ex.Message.ToString());

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
      /// 更新供应商资料列表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public int supplierListUpdate(supplierListModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                supplierListDAL supplierList = new supplierListDAL(tn, conn);
                supplierList.supplierListUpdate(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
      /// 删除一行供应商资料列表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public int supplierListDel(string sNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                supplierListDAL supplierList = new supplierListDAL(tn, conn);
                supplierList.supplierListDel(sNum);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
